package ${package.Controller};
import java.net.URI;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import ${package.Entity}.${entity};
import ${package.Entity}.dto.${entity}DTO;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import com.ctsi.hndx.common.BasePageForm;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctsi.ssdc.util.HeaderUtil;
import com.ctsi.hndx.common.BaseController;
import com.ctsi.hndx.annotations.ResponseResultVo;
import com.ctsi.hndx.result.ResultCode;
import com.ctsi.hndx.result.ResultVO;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 *
 */

@Slf4j
@RestController
@RequestMapping("/api/${entity?uncap_first}")
@Api(value = "${table.comment!}", tags = "${table.comment!}接口")
public class ${entity}Controller extends BaseController {

    private static final String ENTITY_NAME = "${entity?uncap_first}";

    @Autowired
    private ${table.serviceName} ${entity?uncap_first}Service;



    /**
     *  新增${table.comment!}批量数据.
     */
    @PostMapping("/createBatch")
    @ApiOperation(value = "新增批量", notes = "传入参数")
    public AjaxResult createBatch(@RequestBody List<${entity}DTO> ${entity?uncap_first}List) {
       Boolean  result = ${entity?uncap_first}Service.insertBatch(${entity?uncap_first}List);
       if(result){
           return AjaxResult.success();
       }else {
           return AjaxResult.error(HttpStatus.NOT_MODIFIED);
       }
    }

     /**
     *  新增数据.
     */
    @PostMapping("/create")
    @ApiOperation(value = "新增", notes = "传入参数")
    public AjaxResult<${entity}DTO> create(@RequestBody ${entity}DTO ${entity?uncap_first}DTO) throws URISyntaxException {
        ${entity}DTO result = ${entity?uncap_first}Service.create(${entity?uncap_first}DTO);
        return AjaxResult.success(result);
    }

    /**
     *  更新存在数据.
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新存在数据", notes = "传入参数")
    public AjaxResult update(@RequestBody ${entity}DTO ${entity?uncap_first}DTO) {
	    Assert.notNull(${entity?uncap_first}DTO.getId(), "general.IdNotNull");
        int count = ${entity?uncap_first}Service.update(${entity?uncap_first}DTO);
        if(count > 0 ){
            return AjaxResult.success();
        }else {
            return AjaxResult.error(HttpStatus.NOT_MODIFIED);
        }
    }

     /**
     *  删除存在数据.
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除存在数据", notes = "传入参数")
    public AjaxResult delete(@PathVariable Long id) {
        int count = ${entity?uncap_first}Service.delete(id);
        if(count > 0 ){
            return AjaxResult.success();
        }else {
            return AjaxResult.error(HttpStatus.NOT_MODIFIED);
        }
    }

    /**
     * 查询单条数据.
     */
    @GetMapping("/get/{id}")
    @ApiOperation(value = "查询单条数据", notes = "传入参数")
    public AjaxResult get(@PathVariable Long id) {
        ${entity}DTO ${entity?uncap_first}DTO = ${entity?uncap_first}Service.findOne(id);
        return AjaxResult.success(${entity?uncap_first}DTO);
    }

    /**
    *  分页查询多条数据.
    */
    @GetMapping("/query${entity}Page")
    @ApiOperation(value = "翻页查询多条数据", notes = "传入参数")
    public AjaxResult<IPage<${entity}DTO>> query${entity}Page(@RequestBody ${entity}DTO ${entity?uncap_first}DTO, BasePageForm basePageForm) {
        IPage<${entity}DTO> ${entity?uncap_first}List = ${entity?uncap_first}Service.queryListPage(${entity?uncap_first}DTO, basePageForm);
        return AjaxResult.success(${entity?uncap_first}List);
    }

   /**
    * 查询多条数据.不分页
    */
   @GetMapping("/query${entity}")
   @ApiOperation(value = "查询多条数据", notes = "传入参数")
   public AjaxResult<List<${entity}DTO>> query${entity}(${entity}DTO ${entity?uncap_first}DTO) {
       List<${entity}DTO> list = ${entity?uncap_first}Service.queryList(${entity?uncap_first}DTO);
       return AjaxResult.success(list);
   }

}
